#!/usr/bin/env python
import sys
import time
from getpass import getpass
from textwrap import TextWrapper

import tweepy

from memcache import memcache
import memcacheq
            
class StreamWatcherListener(tweepy.StreamListener):
    mq = memcacheq.MemcacheQueue('app_tweets', memcache.Client(['127.0.0.1:11211']))
    
    def on_status(self, status):
    
        try:
            self.mq.add(status)            
            print len(self.mq)

        except:
            print "Unexpected error:", sys.exc_info()[0]
        


def main():
    username='mmacxm'
    password='mmacx2'
    filter = ['iphone','iphones','ipod','ipods','app','apps','appstore', 'appstores', 'itunes','itune']
    #filter = ['app']
    #filter = ['obama']
	
    stream = tweepy.Stream(username, password, StreamWatcherListener(), timeout=None)    
    stream.filter(None, filter)


if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print '\nGoodbye!'
